package love.contact;

import wwk.common.widget.NavigationBar;
import love.contact.engine.Engine;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import com.baidu.mobstat.StatService;

/**
 * @author wangweike
 * @create_date 2011-12-27
 * @update_date 2011-12-27
 */

public class BaseActivity extends Activity
{
	public Engine engine;
	
	public void onCreate(Bundle icicle)
	{
		super.onCreate(icicle);  
		requestWindowFeature(Window.FEATURE_NO_TITLE);
	}
	
	public void onBackPressed() 
	{
		Activity parentActivity=this.getParent();
		/*
		boolean isParentNav=(parentActivity instanceof NavigationActivity);
		if(isParentNav)
		{
			 ((NavigationActivity)getParent()).onBackPressed();
		}
		*/
		if(parentActivity!=null)
		{
			parentActivity.onBackPressed();
		}
		else
		{
			super.onBackPressed();
		}
	}
	
	public boolean onPrepareOptionsMenu(Menu menu) 
	{
		  return super.onPrepareOptionsMenu(menu);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) 
	{		
		if(isAbleToCallSuper())
		{
			return super.onCreateOptionsMenu(menu);
		}

		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item)
	{
		if(isAbleToCallSuper())
		{
			return super.onOptionsItemSelected(item);
		}
	
		return true;
	}
	
	private boolean isAbleToCallSuper()
	{
		boolean isParentNav=(getParent() instanceof NavigationActivity);
		if(!isParentNav || ((NavigationActivity)getParent()).isAbleToCallNav())
		{
			return true;
		}
		
		return false;
	}
	
	public void onStart()
	{
		super.onStart();
		
		/*
		Engine.instance().unregisterContentObserver(this);
		
		if(engine==null)
		{
			engine=Engine.instance();
		}
		else
		{
			if(engine!=Engine.instance())
			{
				finish();
			}
		}
		*/
		
		NavigationBar navigationBar=(NavigationBar)this.findViewById(R.id.navBar);
		if(navigationBar!=null)
		{
			navigationBar.activity=this;
		}
	}
	
	public void onPause()
	{
		super.onPause();
		
		StatService.onPause(this);
	}
	
	public void onResume()
	{
		super.onResume();
		
		StatService.onResume(this);
	}
	
	public void onStop()
	{
		super.onStop();
		
		/*
		Engine.instance().registerContentObserver(this);
		 */
	}
}
